package main.java.com.epam;

import java.io.IOException;
import java.io.InputStream;

public class CompilationException extends Exception{
	
	private static final long serialVersionUID = 1L;
	
	private Process process;
	private String message;

	CompilationException(Process process, String message) {
		this.process = process;
		this.message = message;
	}

	@Override
	public String toString() {
		return getProcessMessage();
	}

	private String getProcessMessage() {
		InputStream in = process.getErrorStream();
		byte[] b = new byte[10000];
		int c = 0;
		try {
			c = in.read(b);
		} catch (IOException e) {
			System.out.println("-------------" + e);
		}
		try {
			return message + "\r\n" +
					new String(b, 0, c, System.getProperty("file.encoding"));
		} catch (Exception e) {
			System.out.println("=================" + e);
			return e.getMessage();
		}
	}
}
